//
//  ViewController.m
//  TestColos
//
//  Created by l t on 2021/3/7.
//

#import "ViewController.h"
#import "HRColorPickerView.h"
#import "HRColorMapView.h"
#import "HRBrightnessSlider.h"
@interface ViewController ()

@end

@implementation ViewController
{
id <HRColorPickerViewControllerDelegate> __weak delegate;
HRColorPickerView *colorPickerView;
UIColor *_color;
BOOL _fullColor;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}
- (id)initWithColor:(UIColor *)defaultColor fullColor:(BOOL)fullColor {
    self = [super initWithNibName:nil bundle:nil];
    if (self) {
        _color = defaultColor;
        _fullColor = fullColor;
    }
    return self;
}
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    if (self.delegate) {
        [self.delegate setSelectedColor:colorPickerView.color];
    }
    
    
}
- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    colorPickerView.frame = (CGRect) {.origin = CGPointZero, .size = self.view.frame.size};

//    if ([self respondsToSelector:@selector(topLayoutGuide)]) {
//        CGRect frame = colorPickerView.frame;
//        frame.origin.y = self.topLayoutGuide.length;
//        frame.size.height -= self.topLayoutGuide.length;
//        colorPickerView.frame = frame;
//    }
    self.view.backgroundColor = [UIColor redColor];
}
-(void)loadView{
    
    self.view = [[UIView alloc] init];
    self.view.backgroundColor = [UIColor whiteColor];
    
    
    
    

    colorPickerView = [[HRColorPickerView alloc] init];
    colorPickerView.color = _color;
    

    if (_fullColor) {
        HRColorMapView *colorMapView = [[HRColorMapView alloc] init];
        colorMapView.saturationUpperLimit = @1;
        colorMapView.tileSize = @1;
        [colorPickerView addSubview:colorMapView];
        colorPickerView.colorMapView = colorMapView;

        HRBrightnessSlider *slider = [[HRBrightnessSlider alloc] init];
        slider.brightnessLowerLimit = @0;
        [colorPickerView addSubview:slider];
        colorPickerView.brightnessSlider = slider;
    }

//    Please uncomment. If you want to catch the color change event.
//    [colorPickerView addTarget:self
//                        action:@selector(colorWasChanged:)
//              forControlEvents:UIControlEventValueChanged];
//    UIView * v = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
//    [self.view addSubview:v]
    [self.view addSubview:colorPickerView];
}
@end
